﻿using SqlSugar;
using SqlSugarCoreDemo.DBSqlSugar;
using System;
using System.ComponentModel.DataAnnotations;

namespace SqlSugarCoreDemo.Model
{
    /// <summary>
    /// 应用访问日志表
    /// </summary>
    [TenantAttribute(DBTenantIds.Main)]
    [SplitTable(SplitType.Month)]//按月分表 （自带分表支持 年、季、月、周、日）
    [SugarTable("SysAppsAccessLog_{year}{month}{day}", TableDescription = "应用访问日志表")]  //生成表名格式 3个变量必须要有
    public partial class SysAppsAccessLog
    {
        /// <summary>
        /// 访问ID-雪花算法
        /// </summary>
        [Display(Name = "访问ID")]
        [SugarColumn(ColumnDescription = "访问ID", IsPrimaryKey = true)]
        public long id { get; set; }
        /// <summary>
        /// 访问应用ID
        /// </summary>
        [Display(Name = "访问应用ID")]
        [SugarColumn(ColumnDescription = "访问应用ID", DefaultValue = "0")]
        public int appsId { get; set; } = 0;
        /// <summary>
        /// 应用APPID
        /// </summary>
        [Display(Name = "应用APPID")]
        [SugarColumn(ColumnDescription = "应用APPID", ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
        [StringLength(50, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string appId { get; set; }
        /// <summary>
        /// 请求方式：枚举HttpMethodEnum
        /// </summary>
        [Display(Name = "请求方式")]
        [SugarColumn(ColumnDescription = "请求方式", IsNullable = true, DefaultValue = "1")]
        public byte requestMethod { get; set; } = 1;
        /// <summary>
        /// 请求URL（XSS等过滤保存）
        /// </summary>
        [Display(Name = "请求URL")]
        [SugarColumn(ColumnDescription = "请求URL", ColumnDataType = "nvarchar", Length = 1500, IsNullable = true)]
        [StringLength(1500, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string requestUrl { get; set; }
        /// <summary>
        /// 请求Header,Json格式(非生产环境记录,不记录Token)：{"Appid","Version","Timestamp","Apps-Sign"}（XSS等过滤保存）
        /// </summary>
        [Display(Name = "请求Header")]
        [SugarColumn(ColumnDescription = "请求Header", ColumnDataType = "nvarchar", Length = 500, IsNullable = true)]
        [StringLength(500, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string requestHeader { get; set; }
        /// <summary>
        /// 请求表单正文（XSS等过滤保存）
        /// </summary>
        [Display(Name = "请求表单正文")]
        [SugarColumn(ColumnDescription = "请求表单正文", ColumnDataType = "nvarchar", Length = 2000, IsNullable = true)]
        [StringLength(2000, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string requestBody { get; set; }
        /// <summary>
        /// 请求IP
        /// </summary>
        [Display(Name = "请求IP")]
        [SugarColumn(ColumnDescription = "请求IP", ColumnDataType = "nvarchar", Length = 30, IsNullable = true)]
        [StringLength(30, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string requestIp { get; set; }
        /// <summary>
        /// 请求时间
        /// </summary>
        [Display(Name = "请求时间")]
        [SplitField]  //分表字段：如类型为string时，按当前value值当表后缀名
        [SugarColumn(ColumnDescription = "请求时间")]
        public DateTime? requestTime { get; set; }
        /// <summary>
        /// 请求状态 ：1 请求完成，2 请求出错
        /// </summary>
        [Display(Name = "请求状态")]
        [SugarColumn(ColumnDescription = "请求状态", DefaultValue = "1")]
        public byte state { get; set; } = 1;
        /// <summary>
        /// 响应内容（XSS等过滤保存）
        /// </summary>
        [Display(Name = "响应内容")]
        [SugarColumn(ColumnDescription = "响应内容", ColumnDataType = "nvarchar", Length = 2000, IsNullable = true)]
        [StringLength(2000, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string responseData { get; set; }
        /// <summary>
        /// 响应时间
        /// </summary>
        [Display(Name = "响应时间")]
        [SugarColumn(ColumnDescription = "响应时间", IsNullable = true)]
        public DateTime? responseTime { get; set; }
        /// <summary>
        /// 访问耗时（秒）
        /// </summary>
        [Display(Name = "访问耗时(秒)")]
        [SugarColumn(ColumnDescription = "访问耗时(秒)", DefaultValue = "0")]
        public decimal loadSecond { get; set; } = 0;
        /// <summary>
        /// 客户端信息，JSON格式：{ os:操作系统, device:设备名称, browser:浏览器类型 }（XSS等过滤保存）
        /// </summary>
        [Display(Name = "客户端JSON信息")]
        [SugarColumn(ColumnDescription = "客户端JSON信息", ColumnDataType = "nvarchar", Length = 2000)]
        [StringLength(2000, ErrorMessage = "【{0}】不能超过{1}长度")]
        public string clientInfo { get; set; }
    }
}
